/**
 * Created by Baggio on 2018-5-7.
 */
$(function () {
    getData(1);
});

function getData(page) {
    var mediaType=$("#mediaType").val();
    var url="/pioneer/media/getMediaList.html";
    var postData={mediaType:mediaType,pageSize:20,page:page};
    $.ajax({
        type: 'POST',
        url: url,
        async: true,
        data:postData,
        dataType:'json',
        success: function(data){
            console.log(data);
            if (data.code != 1){
                layer.msg('操作失败!',{icon : 5,time : 1000});
                console.log(data.msg);
                return;
            }
            console.log(data.data);
            if(mediaType==1){
                showVideoData(data.data);
            }
            else
            {
                showVoiceData(data.data);
            }
            if (page > 1) {
                return;
            }

            laypage({
                cont: 'demo1',
                skin: '#f59d00',
                pages: data.data.pages,
                jump: function (obj, first) {
                    if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                        getData(obj.curr);
                    }

                }
            });
        }
    });

}
function showVoiceData(data) {
console.log("showVoiceData");
var html="";
    for(var i=0;i<data.list.length;i++){
    html+="<li>";

    html+="    <div class=\"voicebox\">";
    html+="       <div class=\"voiceimgbox\">";
    html+="         <a href=\"/pioneer/media/playVoice.html?tid="+data.list[i].tid+"\"><img src='"+picPath+"/"+data.list[i].mediaPic+"' alt=\"图片\">";
    html+="         <div class='voiceimgbox_02'><img src='/static/images/web/pioneer/index/u175.png' alt=''></div>";
    html+="         </a>";
    html+="       </div>";
    html+="    <div class=\"voicetitlebox\">";
    html+="     <p>";
    html+="         <a href=\"/pioneer/media/playVoice.html?tid="+data.list[i].tid+"\">"+data.list[i].mediaName+"</a>";
    html+="     </p>";
    html+="     </div>";
    html+="  </div>";

    html+="</li>";

    }
    $(".voicelist").find("ul").html(html);

}function showVideoData(data) {
    console.log("showVideoData")
var html="";
    for(var i=0;i<data.list.length;i++){
        html+="  <li>";

        html+="   <div class=\"videoimg\">";
        html+="        <a href=\"/pioneer/media/playVideo.html?tid="+data.list[i].tid+"\"><img src='"+picPath+"/"+data.list[i].mediaPic+"' alt=\"\">";
        html+="         <div class='videoimg_02'><img src='/static/images/web/pioneer/index/u175.png' alt=''></div>";
        html+="         </a>";
        html+="        </div>";
        html+="      <div class=\"videoname\">";
        html+="      <p><a href=\"/pioneer/media/playVideo.html?tid="+data.list[i].tid+"\">"+data.list[i].mediaName+"</a></p>";
        html+="   </div>";

        html+="    </li>";

    }
    $(".videolist").find("ul").html(html);

}